---
title: ClickHouse Async
---

## Code

```python cookbook/knowledge/vector_db/clickhouse_db/async_clickhouse.py
import asyncio

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.clickhouse import Clickhouse

agent = Agent(
    knowledge=Knowledge(
        vector_db=Clickhouse(
            table_name="recipe_documents",
            host="localhost",
            port=8123,
            username="ai",
            password="ai",
        ),
    ),
    search_knowledge=True,
    read_chat_history=True,
)

if __name__ == "__main__":
    asyncio.run(
        agent.knowledge.add_content_async(url="https://docs.agno.com/introduction/agents.md")
    )

    asyncio.run(
        agent.aprint_response("What is the purpose of an Agno Agent?", markdown=True)
    )
```

## Usage

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install libraries">
    ```bash
    pip install -U clickhouse-connect pypdf openai agno
    ```
  </Step>
  <Step title="Run ClickHouse">
    ```bash
docker run -d \
  -e CLICKHOUSE_DB=ai \
  -e CLICKHOUSE_USER=ai \
  -e CLICKHOUSE_PASSWORD=ai \
  -e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
  -v clickhouse_data:/var/lib/clickhouse/ \
  -v clickhouse_log:/var/log/clickhouse-server/ \
  -p 8123:8123 \
  -p 9000:9000 \
  --ulimit nofile=262144:262144 \
  --name clickhouse-server \
  clickhouse/clickhouse-server
    ```
  </Step>
  <Step title="Set environment variables">
    ```bash
    export CLICKHOUSE_HOST="localhost"
    export CLICKHOUSE_PORT="8123"
    export CLICKHOUSE_USER="ai"
    export CLICKHOUSE_PASSWORD="ai"
    export CLICKHOUSE_DB="ai"
    export OPENAI_API_KEY=xxx
    ```
  </Step>
  <Step title="Run Agent">
    <CodeGroup>
    ```bash Mac
    python cookbook/knowledge/vector_db/clickhouse_db/async_clickhouse.py
    ```

    ```bash Windows
    python cookbook/knowledge/vector_db/clickhouse_db/async_clickhouse.py
    ```
    </CodeGroup>
  </Step>
</Steps>